﻿// <copyright file="Container.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2008-09-23</date>
// <summary>The Silverlight Application</summary>

namespace opensocial
{
    using System;

    /// <summary>
    /// OpenSocial Container
    /// </summary>
    public sealed class Container
    {
        #region Member Data
        /// <summary>
        /// Singleton container
        /// </summary>
        private static MyOpenSpace.MySpaceContainer container;
        #endregion

        #region Constructions
        /// <summary>
        /// Prevents a default instance of the Container class from being created.
        /// </summary>
        private Container() 
        {
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the Container type
        /// </summary>
        public static Type ContainerType { get; set; }
        #endregion

        #region Methods
        /// <summary>
        /// Get the MySpace OpenSocial Container
        /// </summary>
        /// <returns>The single MyOpenSpace container</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "get", Justification = "Mirroring OpenSocial API.")]
        public static MyOpenSpace.MySpaceContainer get()
        {
            try
            {
                if (container == null)
                {
                    container = new MyOpenSpace.MySpaceContainer();
                }
            }
            catch (InvalidOperationException ioe)
            {
                System.Diagnostics.Debug.WriteLine("Not Running in an OpenSocial Container: {0}", ioe.Message);

                return null;
            }

            return container;
        }
        #endregion
    }
}
